//保存选中条件
var optionStorage = function(name) { 
		this.name = name;
		//四个选中条件的id
		this.options = [{name:"newHot",id:"newHot_0",value:"1"},
						{name:"type",id:"type_0",value:""},
						{name:"addr",id:"addr_0",value:""},
						{name:"year",id:"year_0",value:""}];
		this.initColor = "#000";
		this.fcsColor = "#00a7ba";
		
		this.init = function(){
			this.initOptions();
			this.focusOption();
		}
		this.save = function(){
			var record = JSON.stringify(this.options);
			localStorage.setItem(this.name,record);
		}
		this.initOptions = function(){
			//localStorage.removeItem(this.name);
			var record = localStorage.getItem(this.name);
			if(record){
				this.options = JSON.parse(record);
			}else{
				this.save();
			}
		}
		this.focusOption = function(){
			for(var i=0;i<this.options.length;i++){
				if(document.getElementById(this.options[i].id)){
					document.getElementById(this.options[i].id).style.color = this.fcsColor;
				}
			}
		}
		this.blurOption = function(){
			for(var i=0;i<this.options.length;i++){
				if(document.getElementById(this.options[i].id)){
					document.getElementById(this.options[i].id).style.color = this.initColor;
				}
			}
		}
		this.chooseOption = function(name,id,value){
			var strs = id.split("_");
			if(strs[1] == 0 || value.indexOf("全部") != -1){
				value="";
			}
			if(name == "newHot"){
				if(value == 2){
					value="1";
				}else{
					value="2";
				}
			}
			if(name == "year"){
				if(strs[1] == yearlen){
					var lastIdx = parseInt(strs[1])-1;
					var lastyear = $("#"+name+"_"+lastIdx).html();
					params.year = lastyear;
					params.early = true;
					value = lastyear;
				}else{
					params.early = false;
				}
			}
			
			this.blurOption();
			for(var i=0;i<this.options.length;i++){
				if(name == this.options[i].name){
					var option = {"name":name,"id":id,"value":value};
					this.options[i] = option;
				}
			}
			this.save();
			this.focusOption();
		}
	}

function getPageIndex(id){
	if(id.indexOf("_") == -1 || id == "id_1"){
		return 1;
	}else{
		var arr = id.split("_");
		var length = arr.length;
		if(length > 1){
			return parseInt(arr[length-1]);
		}else{
			return 1;
		}
	}
}

function getRowNum(id){
	if(id.indexOf("_") == -1 || id == "id_1"){
		return 1;
	}else{
		var arr = id.split("_");
		var length = arr.length;
		var idx = 0
		if(length > 2){
			idx = parseInt(arr[1]);
		}
		var end = idx%9;
		if(end > 5){
			return 3;
		}else if(end > 2){
			return 2;
		}else{
			return 1;
		}
	}
}

function countTabNum(idx,pageSize){
	var num = (idx-idx%pageSize)/pageSize;
	var add = idx%pageSize==0?0:1;
	return (num + add);
}
